package com.gxc.controller;

import com.gxc.dao.EsRepository;
import com.gxc.entity.Article;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import sun.util.resources.LocaleData;

/**
 * @author 宫新程
 * @since 2019/1/17 2:20 PM
 */
@RestController
public class EsController {

  @Resource private EsRepository esRepository;

  /** 批量保存. */
  @PostMapping("/save")
  public Boolean save(@RequestBody List<Article> params) {
    params.forEach(
        e -> {
          String id = UUID.randomUUID().toString().replace("-", "");
          e.setId(id);
        });
    esRepository.saveAll(params);
    return true;
  }

  /** 根据标题查询. */
  @GetMapping("/title")
  public List<Article> findTitle(@RequestParam("name") String name) {
    return esRepository.findByTitleLike("%" + name + "%");
  }
}
